# Copyright 2020 huanggefan.cn
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

.PYONY: all, test, clean, sync, run, lib

_prefix=dist

all: test clean lib
	@mkdir -p ${_prefix}
	npm run pack

test:
	npm run test

clean:
	npm run clean
	rm -rvf dist
	rm -rvf lib
	rm -vf assets.js
	rm -vf assets.css

sync:
	npm install

run:
	npm run dev

lib:
	@mkdir -p ${_prefix}/js
	@mkdir -p ${_prefix}/css
	tar -xvzf lib.tar.gz
	mv -v lib/* dist/
	rm -rvf lib
	curl https://code.jquery.com/jquery-3.4.1.min.js > assets.js
	curl https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js >> assets.js
	curl https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js >> assets.js
	curl https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/highlight.min.js >> assets.js
	curl https://cdn.jsdelivr.net/npm/marked/marked.min.js >> assets.js
	mv -v assets.js dist/js/assets.js
	curl https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css > assets.css
	curl https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap-grid.min.css >> assets.css
	curl https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap-reboot.min.css >> assets.css
	curl https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.1/styles/atom-one-light.min.css >> assets.css
	mv -v assets.css dist/css/assets.css
